import 'package:flutter/material.dart';
import 'package:shopping_group/entity/selectiont_entity.dart';
import 'package:shopping_group/modle/play/ui/fugojuan_good_paly_page.dart';
import 'package:shopping_group/modle/more/ui/more_good_page.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/object_util.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class MoreGoodDialogPage extends StatefulWidget {
  final String custGroupSpecRelaId;
  final String reBuyImgUrl;
  MoreGoodDialogPage({
    Key key,
    this.custGroupSpecRelaId,
    this.reBuyImgUrl,
  }) : super(key: key);

  @override
  _MoreGoodDialogPageState createState() => _MoreGoodDialogPageState();
}

class _MoreGoodDialogPageState extends State<MoreGoodDialogPage> {
  List<SelectiontEntity> _list = [];
  //StreamSubscription _addSubscription;
  @override
  void initState() {
    super.initState();
    _list
      ..add(SelectiontEntity()
        ..id = '1'
        ..isSelect = true
        ..title = '复购商品')
      ..add(SelectiontEntity()
        ..id = '2'
        ..isSelect = false
        ..title = '复购券');
    // _modifySubscription = eventBus.on<ModifyCarEvent>().listen((event) {

    // });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(
          onTap: () {
            Navigator.of(context).pop();
          },
          child: Container(
            decoration: new BoxDecoration(
              color: Colours.transparent_25,
            ),
            alignment: Alignment.center,
          ),
        ),
        Column(
          children: <Widget>[
            GestureDetector(
              onTap: () {
                // _list.forEach((element) {
                //   if (element.isSelect && '1' == element.id) {
                //     RouteUtil.closeView();
                //     RouteUtil.goParameter(MoreGoodPage(
                //       custGroupSpecRelaId: this.widget.custGroupSpecRelaId,
                //       selectId: element.id,
                //     ));
                //   } else if (element.isSelect && '2' == element.id) {
                //     RouteUtil.closeView();
                //     RouteUtil.goParameter(FuGouJuanGoodPalyPage(
                //       custGroupSpecRelaId: this.widget.custGroupSpecRelaId,
                //     ));
                //   }
                // });

                RouteUtil.closeView();
                RouteUtil.goParameter(FuGouJuanGoodPalyPage(
                  custGroupSpecRelaId: this.widget.custGroupSpecRelaId,
                ));
              },
              child: Container(
                padding: EdgeInsets.only(
                    top: MediaQuery.of(context).size.height / 5),
                child: FadeInImage.assetNetwork(
                  image: ObjectUtil.isEmptyString(this.widget.reBuyImgUrl)
                      ? 'https://lizhengyouxuan.oss-cn-shanghai.aliyuncs.com/lizhengyouxuan/pingtuan/hongbao.png'
                      : this.widget.reBuyImgUrl,
                  placeholder: 'images/picture_loading.png' /* 指定gif */,
                  fit: BoxFit.fill,
                  width: MediaQuery.of(context).size.width,
                ),
              ),
            ),
            // GestureDetector(
            //   onTap: () {},
            //   child: Container(
            //       padding: EdgeInsets.only(
            //         left: MediaQuery.of(context).size.width / 6,
            //       ),
            //       width: MediaQuery.of(context).size.width,
            //       height: 50,
            //       decoration: new BoxDecoration(
            //         color: Colours.transparent,
            //       ),
            //       child: Row(
            //         crossAxisAlignment: CrossAxisAlignment.center,
            //         mainAxisAlignment: MainAxisAlignment.center,
            //         children: _list.map((SelectiontEntity entity) {
            //           return Expanded(child: _showXyView(entity));
            //         }).toList(),
            //       )),
            // ),
          ],
        ),
      ],
    );
  }

  Widget _showXyView(SelectiontEntity entity) {
    return WidgetUtils.getCheckboxIocnView(entity,
        textSize: Dimens.FONT_SIZE_14,
        horizontalPadding: 0,
        textColor: Colours.title_white,
        iconsColor: Colours.title_white, blackCall: () {
      setState(() {
        _list.forEach((element) {
          element.isSelect = false;
        });
        entity.isSelect = true;
      });
    }, verticalPadding: 0);
  }

  @override
  void dispose() {
    super.dispose();
  }
}
